package cn.tedu.fengyuback.common;

import cn.tedu.fengyuback.base.constent.Constant;
import cn.tedu.fengyuback.personal.mapper.PersonalMapper;
import cn.tedu.fengyuback.personal.pojo.dto.FavoritesQuery;
import cn.tedu.fengyuback.personal.pojo.dto.LikesQuery;
import cn.tedu.fengyuback.personal.pojo.vo.ArticlesVO;
import cn.tedu.fengyuback.personal.pojo.vo.FavoritesVO;
import cn.tedu.fengyuback.personal.pojo.vo.LikesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 查看点赞和收藏
 */
public class LikeFavorite {

    private static PersonalMapper personalMapper;

    /**
     * 查询用户是否收藏该文章
     * @param articlesVO
     */
    public static void favoritesQuery(ArticlesVO articlesVO) {
        FavoritesQuery favoritesQuery = new FavoritesQuery();
        favoritesQuery.setArticleId(articlesVO.getId());
        favoritesQuery.setUserId(articlesVO.getUserId());
        FavoritesVO favoritesVO = personalMapper.selectFavorites(favoritesQuery);
        if (favoritesVO != null){//收藏了
            articlesVO.setFavoritesId(favoritesVO.getId());
            articlesVO.setFavoritesStatus(Constant.ARTICLE_LIKE_FAVORITES);
        }else {//没收藏
            articlesVO.setFavoritesStatus(Constant.NOT_ARTICLE_LIKE_FAVORITES);
        }
    }

    /**
     * 查询用户是否点赞该文章
     * @param articlesVO
     */
    public static void likesQuery(ArticlesVO articlesVO) {
        LikesQuery likesQuery = new LikesQuery();
        likesQuery.setArticleId(articlesVO.getId());
        likesQuery.setUserId(articlesVO.getUserId());
        LikesVO likesVO = personalMapper.selectLikes(likesQuery);
        if (likesVO != null){//点赞了
            articlesVO.setLikesId(likesVO.getId());
            articlesVO.setLikesStatus(Constant.ARTICLE_LIKE_FAVORITES);
        }else {//没点赞
            articlesVO.setLikesStatus(Constant.NOT_ARTICLE_LIKE_FAVORITES);
        }
    }
}
